package com.jiazhong.ssm.test06参数验证.controller;


import com.jiazhong.ssm.test06参数验证.pojo.User;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @Auther:shuXin
 */
@RestController
@RequestMapping("user")
public class UserController {
    @PostMapping("register")
    public Object register(@Validated @RequestBody User user, BindingResult result) {
        //进行一个判断
        if (result.hasErrors()) {
            //没有绑定的错误就继续执行，有绑定的错误，就交给这里面的逻辑来进行处理
            Map map = new HashMap();
            map.put("code",400);
            map.put("message","参数绑定错误");
            return map;
        }
        System.out.println(user);
        return "ok";
    }
}
